
#include "AUEffectBase.h"
#include <AudioToolbox/AudioUnitUtilities.h>
#include "FilterVersion.h"
#include "ChannelsSendingTester.h"




//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#pragma mark ____Filter

class Filter : public AUEffectBase
{
public:
	Filter(AudioUnit component): AUEffectBase(component) {}
    
	virtual OSStatus			Version() { return kFilterVersion; }
    
    virtual OSStatus			ProcessBufferLists(
                                                   AudioUnitRenderActionFlags &	ioActionFlags,
                                                   const AudioBufferList &			inBuffer,
                                                   AudioBufferList &				outBuffer,
                                                   UInt32							inFramesToProcess );
	
	virtual	bool				SupportsTail () { return true; }
    virtual Float64				GetTailTime() {return 0.0;}
    virtual Float64				GetLatency() {return 0.0;}
    
private:
    ChannelsSendingTester openCLProc_;
    
};





//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#pragma mark Standard DSP AudioUnit implementation

AUDIOCOMPONENT_ENTRY(AUBaseFactory, Filter)





//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#pragma mark ____Processing

OSStatus        Filter::ProcessBufferLists(
                                           AudioUnitRenderActionFlags &	ioActionFlags,
                                           const AudioBufferList &			inBuffer,
                                           AudioBufferList &				outBuffer,
                                           UInt32							inFramesToProcess )
{
    unsigned int channelsNum = GetNumberOfChannels();
    float** in, **out;
    in = new float*[channelsNum];
    out = new float*[channelsNum];
    
    for(int i=0; i < inBuffer.mNumberBuffers; ++i) {
        in[i] = (float*) inBuffer.mBuffers[i].mData;
        out[i] = (float*) outBuffer.mBuffers[i].mData;
    }
    
    this->openCLProc_.manyChannels(in, channelsNum, inFramesToProcess, out);
    
    
    return noErr;
}



